board = 
[["5","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]
var isValidSudoku = function(board) {
    const rows=new Array(9).fill(0).map(()=>new Set())
    const cols=new Array(9).fill(0).map(()=>new Set())
    const boxes=new Array(9).fill(0).map(()=>new Set())
       for(i=0;i<9;i++)
       {  
        for(j=0;j<9;j++)
        { 
            const num=board[i][j]
            if(num==='.')continue
            if(rows[i].has(num))
            {   
                return false;
            }
            else{
                rows[i].add(num)
            }
            if(cols[j].has(num)){
                return false;
            }
            else{
                cols[j].add(num)
            }
            const boxIndex=Math.floor(i/3)*3+Math.floor(j/3)
            if(boxes[boxIndex].has(num)){
                return false
            }
            else{
                boxes[boxIndex].add(num)
            }
            
        

        } 

       }
       return true


    
};
console.log(isValidSudoku(board));
